package com.example.myapplication.urbansubway;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.Config.RunOnUiThreadTool;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.RoutelistsBean;
import com.example.myapplication.ShuJu.RouteoverviewBean;
import com.example.myapplication.apter.RoutelistsApter;

public class OverviewmappageActivity extends AppCompatActivity {
    private ImageView img;
    private ImageView imgurl;
    private RecyclerView routelist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_overviewmappage);
        initview();
        but_bloak();
        //路线图片
        routeoverview();
        //路线
        routelists();
    }

    private void routelists() {
        OKHttpTool.doNetRequest("prod-api/api/metro/line/list",
                OKHttpTool.GET,
                RoutelistsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        RunOnUiThreadTool.run(OverviewmappageActivity.this, new RunOnUiThreadTool.RunCallback() {
                            @Override
                            public void set() {
                                RoutelistsBean routelistsBean = (RoutelistsBean) obj;
                                if (routelistsBean.getCode() == 200) {
                                    routelist.setAdapter(new RoutelistsApter(OverviewmappageActivity.this,routelistsBean.getData()));
                                    routelist.setLayoutManager(new LinearLayoutManager(OverviewmappageActivity.this));
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OverviewmappageActivity.this.finish();
            }
        });
    }

    private void routeoverview() {
        OKHttpTool.doNetRequest("prod-api/api/metro/city",
                OKHttpTool.GET,
                RouteoverviewBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        RunOnUiThreadTool.run(OverviewmappageActivity.this, new RunOnUiThreadTool.RunCallback() {
                            @Override
                            public void set() {
                                RouteoverviewBean routeoverviewBean = (RouteoverviewBean) obj;
                                if (routeoverviewBean.getCode() == 200) {
                                    Glide.with(OverviewmappageActivity.this).load(TokenBean.IP+routeoverviewBean.getData().getImgUrl()).into(imgurl);
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }


    private void initview() {
        img = findViewById(R.id.img);
        imgurl = findViewById(R.id.imgurl);
        routelist = findViewById(R.id.routelist);
    }
}